﻿using System;
using System.Reflection;

namespace UtilZ.Dotnet.Ex.CommandLineParser
{
    /// <summary>
    /// 命令行选项特性
    /// </summary>
    [AttributeUsage(AttributeTargets.Property)]
    public class CommandLineOptionAttribute : Attribute
    {
        /// <summary>
        /// 选项简称
        /// </summary>
        public string Name { get; private set; } = null;

        /// <summary>
        /// 选项全称
        /// </summary>
        public string FullName { get; private set; } = null;

        /// <summary>
        /// 选项描述
        /// </summary>
        public string Des { get; private set; } = null;

        /// <summary>
        /// 帮助说明信息
        /// </summary>
        public string HelpText { get; private set; } = null;

        /// <summary>
        /// 获取或设置转换器类型
        /// </summary>
        public Type ConverterType { get;  set; } = null;

        /// <summary>
        /// 选项顺序
        /// </summary>
        public int Order { get; set; } = 0;

        /// <summary>
        /// 构造函数初始化
        /// </summary>
        /// <param name="name">选项简称</param>
        /// <param name="fullName">选项全称</param>
        /// <param name="des">选项描述</param>
        /// <param name="helpeText">帮助说明信息</param>
        public CommandLineOptionAttribute(string name, string fullName, string des,  string helpeText)
        {
            this.Name = name;
            this.FullName = fullName;
            this.Des = des;
            this.HelpText = helpeText;
        }


    }

    /// <summary>
    /// 命令行选项值转换器接口
    /// </summary>
    public interface ICommandLineOptionConverter
    {
        /// <summary>
        /// 尝试从字符串转换为值类型数据,包括枚举
        /// </summary>
        /// <param name="proInfo">属性信息</param>
        /// <param name="value">要转换的值</param>
        /// <param name="result">转换结果</param>
        /// <returns>转换成功返回true,失败返回false</returns>
        bool TryConvertTo(PropertyInfo proInfo, string value, out object result);
    }

    /// <summary>
    /// 命令特性
    /// </summary>
    [AttributeUsage(AttributeTargets.Class)]
    public class CommandAttribute : Attribute
    {
        /// <summary>
        /// 命令简称
        /// </summary>
        public string Name { get; private set; } = null;

        /// <summary>
        /// 命令全称
        /// </summary>
        public string FullName { get; private set; } = null;

        /// <summary>
        /// 描述信息
        /// </summary>
        public string Des { get; private set; } = null;

        /// <summary>
        /// 构造函数初始化
        /// </summary>
        /// <param name="name">命令简称</param>
        /// <param name="fullName">命令全称</param>
        /// <param name="des">描述信息</param>
        public CommandAttribute(string name, string fullName, string des)
        {
            this.Name = name;
            this.FullName = fullName;
            this.Des = des;
        }

    }

}
